<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <link th:href="@{/layui/css/layui.css}" href="../../static/layui/css/layui.css" rel="stylesheet"/>
</head>
<body>

<table class="layui-hide" id="recommendTable" lay-filter="recommendTable"></table>

<script type="text/html" id="rightBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script  th:src="@{/layui/layui.js}"></script>
<script>
    layui.use(['table','layer'], function(){
        var table = layui.table,
            $=layui.jquery,
            layer=layui.layer;


        table.render({
            elem: '#recommendTable'
            ,url:'/article/queryRecommendList'
            ,cols: [  [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80}
                ,{field:'title', title:'标题', width:320}
                ,{fixed: 'right', title:'操作', toolbar: '#rightBar', width:150}
            ]  ]
        });


        //监听行工具事件
        table.on('tool(recommendTable)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        url:"/article/deleteRecommend",
                        type:"POST",
                        data:{"id":data.id},
                        success:function (e) {
                            if(e.success){
                                obj.del();
                                layer.close(index);
                            }else{
                                alert(e.msg);
                            }
                        },dataType:"json"
                    });
                });
            }
        });
    });
</script>
</body>
</html>